﻿using Ls.Core;
using Ls.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Ls.Web.Admin.Models
{
    public class UserService : BaseService
    {
        public override string CacheKeyPre => "USER_";
        public UserService() : base("Default", "sys_users", "用户表")
        {
        }
        /// <summary>
        /// 过去用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public sys_user GetUserInfo(long userId)
        {
            string key = CacheKeyPre + "INFO_" + userId;
            sys_user user = CacheHelper.Get<sys_user>(key);
            if (user == null)
            {
                user = db.Sql("select a.*,b.org_name from sys_users as a left join sys_org as b on a.org_id=b.org_id where user_id=@user_id").Parameter("user_id", userId).QuerySingle<sys_user>();
                if (user != null) CacheHelper.Set(key, user);
            }
            return user;
        }
    }


    /// <summary>
    /// 用户表 用户表
    /// </summary> 
    public class sys_user
    { 
        /// <summary>
        /// 用户Id
        /// </summary>     
        public long user_id { get; set; }

        /// <summary>
        /// 用户账号
        /// </summary>    
        public string username { get; set; }

        /// <summary>
        /// 密码
        /// </summary>      
        public string userpwd { get; set; }

        /// <summary>
        /// 真是姓名
        /// </summary>    
        public string realname { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>     
        public string nickname { get; set; }

        /// <summary>
        /// 性别 性别 0 未知  1 男 2 女
        /// </summary>       
        public int sex { get; set; }

        /// <summary>
        /// 密码加密的盐
        /// </summary>    
        public string salt { get; set; }

        /// <summary>
        /// qq
        /// </summary>     
        public string qq { get; set; }

        /// <summary>
        /// 微信
        /// </summary>     
        public string weixin { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>     
        public string email { get; set; }

        /// <summary>
        /// 电话号码
        /// </summary>       
        public string phone { get; set; }
  
        /// <summary>
        /// 是否超级管理员 是否超级管理员 0 否 1 是
        /// </summary>         
        public int is_sup { get; set; }

        /// <summary>
        /// 用户类型 0 工厂用户 1 运营商用户 2 加盟商用户
        /// </summary>         
        public int user_type { get; set; }

        /// <summary>
        /// 身份证号码
        /// </summary>   
        public string idcard { get; set; }

        /// <summary>
        /// 公司Id
        /// </summary>       
        public long org_id { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>       
        public string org_name { get; set; }
        /// <summary>
        /// 用户状态
        /// </summary>         
        public int user_status { get; set; }

    }
}
